﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TodayWorks.aspx.cs" Inherits="ZLDC.Estate.Quantify.TodayWorks" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>今日工作</title>
    <base target="_self" />
    <link href="../css/main1.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        td
        {
            height: 10px;
        }
    </style>

    <script type="text/javascript">
        function Show() {
            document.getElementById("div2").style.display = "";
            document.getElementById("div3").style.display = "";
            document.getElementById("div4").style.display = "";
            document.getElementById("div5").style.display = "";
        }
        var totalnum = 0;

        function Gen(t) {
            var total = 0;
            var value_di = '<%=value %>';
            var tr = t.parentNode;
            var rowIndex = t.parentNode.parentNode.rowIndex;


            var gvView = document.getElementById("grView2");

            var rowIndex1 = gvView.rows.length - 1; //GridView 列表的最后一行

            if (t.value != "" || !isNaN(parseInt(t.value, 10))) {
                var scores = gvView.rows[rowIndex].cells[3].innerText; //分数
                var hidquantity = gvView.rows[rowIndex].cells[1].childNodes[4]; //数量 hid
                var count = gvView.rows[rowIndex].cells[2].childNodes[2].outerText; //数量
                var checkbox = gvView.rows[rowIndex].cells[1].childNodes[0]; //是否打勾
                var quantity = gvView.rows[rowIndex].cells[5].childNodes[0].value; //完成数量
                if (checkbox.disabled) {

                    if (parseInt(quantity) < parseInt(hidquantity.value)) {

                        t.value = hidquantity.value;
                    }
                }
                else {
                    if (!checkbox.checked) {
                        t.value = '0';
                        return false;
                    }
                }
                var hscores = gvView.rows[rowIndex].cells[4].innerText; //最高分

                var sum;
                if (hscores == 0) {
                    sum = parseInt(t.value) * (scores / count); //单项总分
                }
                else {
                    sum = parseInt(t.value) * (scores / count); //单项总分

                    if (sum >= hscores) {
                        sum = hscores;
                    }
                }

                gvView.rows[rowIndex].cells[6].getElementsByTagName("input")[0].innerText = parseInt(sum);


                for (var i = 1; i < rowIndex1; i++) {

                    if (!isNaN(parseInt(gvView.rows[i].cells[6].childNodes[0].value))) {

                        total += parseInt(gvView.rows[i].cells[6].childNodes[0].value);

                    }
                }
                totalnum = total;
                gvView.rows(rowIndex1).cells(6).innerText = "总分：" + total;

            }
            else {

                // gvView.rowIndex.cells[5].getElementsByTagName("input")[0].innerText = "";

                for (var i = 1; i < rowIndex1; i++) {

                    if (!isNaN(parseInt(gvView.rows[i].cells[6].childNodes[0].value, 10))) {
                        total = parseInt(total, 10) + parseInt(gvView.rows[i].cells[6].childNodes[0].value, 10);
                    } else {
                        total = total;
                    }
                }

                gvView.rows(rowIndex1).cells(6).innerText = "总分：" + total;

            }
        }


        function btnyz() {

            var value_di = '<%=value %>';
            var gvView = document.getElementById("grView2");
            var rowIndex1 = gvView.rows.length - 1; //GridView 列表的最后一行
            var count = 0;
            for (var i = 1; i < rowIndex1; i++) {
                var chk = gvView.rows[i].cells[0].childNodes[0].checked;
                var eb = gvView.rows[i].cells[0].childNodes[0].disabled;
                if (chk || eb == false) {
                    count++;
                }
            }
            if (count <= 0) {
                alert('请选择工作项!');
                return false;
            }


            if (totalnum < value_di) {
                alert('不能低于最低总分!');
                return false;
            }

            return true;
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <table width="700px" border="0" cellpadding="0" bgcolor="#CCCCCC">
        <tr>
            <td width="100%" style="margin-left: 20%" bgcolor="#F7F7F7">
                <strong>
                    <%=username %>早上好:</strong><a id="afk" runat="server"></a>
            </td>
        </tr>
        <tr>
            <td align="center" width="100%" style="" bgcolor="#F7F7F7">
                <div runat="server" id="divtdcenter" style="color: Red">
                </div>
      
        </td></tr>
        <%--<tr>
                <td width="100%"  bgcolor="#F7F7F7" >
                <table style="text-align:center">
                <tr><td>
                   <div class="f_l rqieh"  id="div_tab">
                                <a class="y" style="cursor: pointer;width:100px;height:24px" onclick="Show();">今日工作</a>
                   </div>
                </td></tr>
                </table>
                </td>
            </tr>--%>
        <%-- <tr>
                <td bgcolor="#F7F7F7" align="center">
                        <asp:Label ID="lblText1" runat="server" Text=""></asp:Label><br/>
                </td>
            </tr>--%>
        <%--<tr>
                <td bgcolor="#F7F7F7" align="left">
                    <div style="" id="div2" runat="server">
                        <asp:Label ID="Label3" runat="server" Text="今天您的经理为您精心准备了："></asp:Label><br/>
                        
                     </div>
                     <div style="" runat="server" id="div4">
                        <asp:Label ID="Label5" runat="server" Text="您的经理请您自行安排工作："></asp:Label><br/>
                     </div>
                </td>
            </tr>--%>
        <tr>
            <td bgcolor="#F7F7F7" style="height: 460px">
                <div style="height: 340px; overflow-x: auto; overflow-y: auto; width: 100%;" runat="server"
                    id="div3">
                    <asp:GridView ID="grView1" Style="text-align: center" runat="server" AutoGenerateColumns="False"
                        Width="100%" ShowFooter="True" OnRowDataBound="grView1_RowDataBound">
                        <Columns>
                            <asp:TemplateField HeaderText="量化工作" ItemStyle-Width="45%">
                                <ItemTemplate>
                                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("basisname") %>'></asp:Label>
                                    <asp:Label ID="lblquantity" runat="server" Text='<%# Bind("quantity") %>'></asp:Label>
                                    <asp:Label ID="lblunit" runat="server" Text='<%# Bind("unit") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="分数" ItemStyle-Width="45%">
                                <ItemTemplate>
                                    <asp:Label ID="lblpoint" runat="server" Text='<%# Bind("SinglePoint") %>'></asp:Label>
                                </ItemTemplate>
                                <FooterTemplate>
                                    <asp:Label ID="lbltotal" runat="server" Text=""></asp:Label>
                                </FooterTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <HeaderStyle BackColor="#d3eaef" CssClass="fixHeaderStyle" />
                    </asp:GridView>
                </div>
                <div style="height: 460px; width: 100%; overflow-x: auto; overflow-y: auto; position: absolute;
                    top: 22px;" runat="server" id="div5">
                    <asp:GridView ID="grView2" Style="text-align: center" runat="server" AutoGenerateColumns="False"
                        Width="97%" ShowFooter="True" OnRowDataBound="grView2_RowDataBound" OnPageIndexChanging="grView2_PageIndexChanging"
                        PageSize="5" OnRowCreated="grView2_RowCreated">
                        <RowStyle Height="10px" />
                        <Columns>
                            <asp:TemplateField HeaderText="类别">
                                <ItemTemplate>
                                    <%# GetColor(Eval("TypeName").ToString())%>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="">
                                <ItemTemplate>
                                    <asp:CheckBox ID="cbxCheck" Enabled='<%#  ZLDC.Topo.BLL.Estate.lp_Package.GetEnabled(Eval("Reserve1").ToString()) %>'
                                        Checked='<%# ZLDC.Topo.BLL.Estate.lp_Package.Gettr(Eval("Other1").ToString()) %>'
                                        runat="server" onclick="ck(this)" />
                                    <asp:HiddenField ID="hidBasisID" runat="server" Value='<%# Bind("BasisID") %>' />
                                    <asp:HiddenField ID="hidQuantity" runat="server" Value='<%# Bind("Quantity") %>' />
                                    <asp:HiddenField ID="hidid" runat="server" Value='<%# Bind("ID") %>' />
                                    <asp:HiddenField ID="hidHighest" runat="server" Value='<%# Bind("Highest") %>' />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="数量">
                                <ItemTemplate>
                                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("name") %>'></asp:Label>
                                    <asp:Label ID="lblquantity" runat="server" Text='<%# Bind("SingleNumber") %>'></asp:Label>
                                    <asp:Label ID="lblunit" runat="server" Text='<%# Bind("unit") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="得分">
                                <ItemTemplate>
                                    <asp:Label ID="lblpoint" runat="server" Text='<%# Bind("point") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="最高分">
                                <ItemTemplate>
                                    <asp:Label ID="lblScore" runat="server" Text='<%# Bind("Highest") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="完成数量">
                                <ItemTemplate>
                                    <asp:TextBox ID="txtCount" Width="40px" Height="14px" Text='<%# Bind("Quantity") %>'
                                        onkeyup="Gen(this)" MaxLength="3" runat="server"></asp:TextBox>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="单项总分">
                                <ItemTemplate>
                                    <asp:TextBox ID="txtSumScors" Width="40px" Text='<%# Bind("SinglePoint") %>' Height="14px"
                                        ReadOnly="true" runat="server"></asp:TextBox>
                                </ItemTemplate>
                                <FooterTemplate>
                                    <asp:Label ID="lbltotal" runat="server" Text="0"></asp:Label>
                                </FooterTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <HeaderStyle BackColor="#d3eaef" CssClass="fixHeaderStyle" />
                    </asp:GridView>
                </div>
                <%-- <div  style="position:absolute; top:362px; right:16%">
                  
                   <font color="red">总分：<asp:Label ID="lblSum" runat="server" Text="123" ></asp:Label></font>
                    
                 </div>--%>
            </td>
        </tr>
        <tr>
            <td bgcolor="#F7F7F7" align="center">
                <asp:Button ID="btnSave1" runat="server" Text="好的" OnClick="btnSave1_Click" />
                <asp:Button ID="btnSave2" runat="server" Text="确认" OnClick="btnSave2_Click" OnClientClick="return btnyz()" /><a
                    id="anum" runat="server" style="color: Red"></a>
            </td>
        </tr>
    </table>

    <script type="text/javascript">
        function ck(obj) {
            var total = 0;
            var tr = obj.parentNode;
            var rowIndex = obj.parentNode.parentNode.rowIndex;

            var gvView = document.getElementById("grView2");

            var rowIndex1 = gvView.rows.length - 1; //GridView 列表的最后一行

            for (var i = 1; i < rowIndex1; i++) {
                var count = gvView.rows[i].cells[5].childNodes[0]; //完成数量
                var checkbox = gvView.rows[i].cells[1].childNodes[0]; //是否打勾
                var hidquantity = gvView.rows[i].cells[1].childNodes[4]; //数量 hid
                var numcount = gvView.rows[i].cells[4].childNodes[0]; //最高分
                var last = gvView.rows[i].cells[6].childNodes[0]; //单项总
                if (checkbox.disabled) {

                    if (parseInt(count.value) < parseInt(hidquantity.value)) {

                        count.value = hidquantity.value;
                    }

                }
                else {
                    if (checkbox.checked) {
                        count.disabled = false;
                    }
                    else {
                        count.disabled = true;
                        count.value = '';
                        numcount.value = '';
                        last.value = '0';
                    }
                }
                if (!isNaN(parseInt(gvView.rows[i].cells[6].childNodes[0].value, 10))) {
                    total += parseInt(gvView.rows[i].cells[6].childNodes[0].value);
                } else {
                    total = total;
                }

            }
            total = isNaN(total) == true ? 0 : total;
            gvView.rows(rowIndex1).cells(6).innerText = "总分：" + total;


        }

        var total = 0;
        var gvView = document.getElementById("grView2");

        if (gvView != null) {
            var rowIndex1 = gvView.rows.length - 1; //GridView 列表的最后一行
            for (var i = 1; i < rowIndex1; i++) {

                if (!isNaN(parseInt(gvView.rows[i].cells[6].childNodes[0].value, 10))) {
                    total += parseInt(gvView.rows[i].cells[6].childNodes[0].value);
                }
            }


            total = isNaN(total) == true ? 0 : total;
            totalnum = total;
            gvView.rows(rowIndex1).cells(6).innerText = "总分：" + total;
        }
    </script>

    </form>
</body>
</html>
